#include <vector>

using std::vector;

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        vector<int> ret(nums);
        for (int i = 1; i < nums.size() - 1; i++) {
            ret[i] *= ret[i - 1];
        }
        int k = 1;
        for (int i = nums.size() - 1; i > 0; i--) {
            ret[i] = k * ret[i - 1];
            k *= nums[i];
        }
        ret[0] = k;
        return ret;
    }
};